'use strict';
const {parseTime} = require("../../utils");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, TEXT } = app.Sequelize;
    const Notice = app.model.define(
        'Notice',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            title: {type: STRING(255), allowNull: false, comment: '公告标题'},
            position: {type: STRING(50), allowNull: false, comment: '公告位置：interview-面试，written-笔试'},
            content: {type: TEXT, allowNull: true, comment: '公告内容'},
            status: {type: INTEGER, defaultValue: 1, comment: '状态：1-启用，0-禁用'},
            sort: {type: INTEGER, defaultValue: 0, comment: '排序，数字越小越靠前'},
            start_time: {
                type: DATE,
                allowNull: true,
                comment: '开始时间',
                get() {
                    return parseTime(this.getDataValue('start_time'));
                }
            },
            end_time: {
                type: DATE,
                allowNull: true,
                comment: '结束时间',
                get() {
                    return parseTime(this.getDataValue('end_time'));
                }
            },
            view_count: {type: INTEGER, defaultValue: 0, comment: '浏览次数'},
            is_top: {type: INTEGER, defaultValue: 0, comment: '是否置顶：1-是，0-否'},
            is_recommend: {type: INTEGER, defaultValue: 0, comment: '是否推荐：1-是，0-否'},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'notice',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    Notice.associate = function() {
        // 公告表暂时没有关联关系
    }
    
    return Notice;
}; 